package com.fulong.service.Job;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fulong.entity.DeviceManageInfoEntity;
import com.fulong.service.DeviceLendRecordService;
import com.fulong.service.DeviceManageInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Logger;


@EnableScheduling
@Configuration
public class DeviceJob {
    @Autowired
    DeviceLendRecordService deviceLendRecordService;
    @Autowired
    DeviceManageInfoService deviceManageInfoService;
    /*
    * 设备定时更新任务
    * */
    @Async
    @Scheduled(cron = "0 0 23 * * ?")
    public void updateCancelStatus(){
        boolean b = deviceLendRecordService.updateApproverRecoder();
        boolean updateperoid = deviceManageInfoService.update(
                new UpdateWrapper<DeviceManageInfoEntity>()
                        .setSql("device_manage_info.period =  device_manage_info.period-1")
                        .gt("period" , 0));
        boolean updatestatus = deviceManageInfoService.update(new UpdateWrapper<DeviceManageInfoEntity>()
                .eq("peroid", 0)
                .set("status", 1));
        Logger.getGlobal().info("设备状态更新："+updatestatus);
        Logger.getGlobal().info("设备周期更新："+updateperoid);
        Logger.getGlobal().info("审批状态更新："+b);
    }

}
